/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @author Stupi
 */
public class FunctionPanel extends javax.swing.JPanel {

    private int [] xValues;
    private int [] yValues;
    
    private int xPlus;
    private int yPlus;
    private int xMinus;
    private int yMinus;
    
    private int ratio;
    /**
     * Creates new form FunctionPanel
     */
    public FunctionPanel( int [] xValues, int [] yValues , int xMinus, int xPlus, int yMinus, int yPlus) {
        initComponents();
        
        this.xValues = xValues;
        this.yValues = yValues;
        
        this.xMinus = xMinus;
        this.xPlus= xPlus;
        this.yMinus = yMinus;
        this.yPlus = yPlus;
        
        ratio = 50;
        
        setVisible(true);
        
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        Graphics2D g2d = (Graphics2D) g;
        
        g2d.setBackground(Color.WHITE);
        
        int widthX = (xPlus - xMinus)*ratio;
        int heightY = (yPlus - yMinus)*ratio;
        
        setSize(widthX, heightY);
        
       if (xPlus > 0 && xMinus < 0) {
            int xCoo = Math.abs(xMinus)*ratio;
            g2d.drawLine(xCoo, 0, xCoo, heightY);
        }
        
        if (yPlus > 0 && yMinus < 0) {
            int yCoo = Math.abs(yMinus)*ratio;
            g2d.drawLine(0, yCoo, widthX, yCoo);
        }
        
        
        for (int i = 0; i < xValues.length; i++) {
            
            int x = xValues[i];
            int y = yValues[i];
            g2d.drawLine(x, y, x, y);
        }
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
